package com.iias.common.util;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class SystemInfo {

    /**
     * 获取本机的网络IP
     * @return
     */
    public static List<String> getNetWorkIp(){
        final List<String> ips = new ArrayList<String>();
        Enumeration<NetworkInterface> networkInterfaces = null;
        try {
            networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while(networkInterfaces.hasMoreElements()){
                networkInterfaces.nextElement().getInterfaceAddresses().forEach(address ->{
                    ips.add(address.getAddress().getHostAddress());
                });
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
      return ips;
    }

    public static boolean isCurrent(String ip){
        List<String> netWorkIp = getNetWorkIp();
        if (netWorkIp.contains(ip))return true;
        return false;
    }

}
